angular.module('ted.service', [])
.factory('Ted',['$http', function($http){
    return {
        getTopics: function(callback){
            $http.get('/_api/topics').
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },       
        getTopic: function (id, callback) {
            $http.get('/_api/topic/'+id).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },
        getMenus: function(){
            return [
                {label:'首页', url:"#!/topic/hot",actived:true},
                {label:'往期回顾', url:"#!/topics"}
            ];
        },
        getTopicByTag: function(tag,callback){
            $http.get('/_api/tag/'+tag).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },
        addScore: function(tid,score,callback){
            $http.post('/_api/score',{tid:tid,score:score}).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        }                          
    };
}]);

